package shining365.programmableweb.data.app;

import java.io.IOException;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Map;
import java.util.TimeZone;
import java.util.Map.Entry;

import javax.xml.bind.JAXBException;

import org.junit.Test;

public class OneDayApiIndexes {

	@Test
	public void computeOneDayCentrality() throws IOException, ParseException,
			JAXBException {
		Date date = theDay.getTime();
		ApiCentrality ac = new ApiCentrality(date);
		Map<String, Double> api2centrality = ac.getApiCentralities();

		for (Entry<String, Double> entry : api2centrality.entrySet()) {
			System.out.println(entry.getKey() + "\t" + entry.getValue());
		}
	}

	@Test
	public void computeOneDayActiveness() throws IOException, ParseException,
			JAXBException {
		Date newDate = theDay.getTime();
		theDay.add(Calendar.DAY_OF_MONTH, -7 * 13);
		Date oldDate = theDay.getTime();
		ApiActiveness ac = new ApiActiveness(oldDate, newDate);
		Map<String, Double> api2activeness = ac.getApiActiveness();

		for (Entry<String, Double> entry : api2activeness.entrySet()) {
			System.out.println(entry.getKey() + "\t" + entry.getValue());
		}
	}

	private static final Calendar theDay;
	static {
		theDay = 
			new GregorianCalendar(2009, Calendar.SEPTEMBER, 20, 0, 0, 0);
		theDay.setTimeZone(TimeZone.getTimeZone("UTC"));
	}
}
